package com.qhyiyun.baseweb.util;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequestWrapper;

import java.util.HashMap;
import java.util.Map;

public class DecryptRequestWrapper extends HttpServletRequestWrapper {

    private Map<String, String[]> modifiedParameters;

    public DecryptRequestWrapper(HttpServletRequest request, Map<String, String> decryptedParams) {
        super(request);
        modifiedParameters = new HashMap<>(request.getParameterMap());
        decryptedParams.forEach((key, value) -> modifiedParameters.put(key, new String[]{value}));
    }

    @Override
    public String getParameter(String name) {
        String[] values = modifiedParameters.get(name);
        return values != null && values.length > 0 ? values[0] : null;
    }

    @Override
    public Map<String, String[]> getParameterMap() {
        return modifiedParameters;
    }

    @Override
    public String[] getParameterValues(String name) {
        return modifiedParameters.get(name);
    }
}
